/*
 * Copyright (c) 2011 Team A CS2340. All rights reserved.
 */

package edu.gatech.teama.doctorsoffice.net;

import java.util.List;

import edu.gatech.teama.doctorsoffice.model.Patient;
import edu.gatech.teama.doctorsoffice.server.DataModel;

/**
 * Specifies the name of a <code>Patient</code> to look up
 * in the data model.
 * @author Team A
 * @version 1.0
 *
 */
public class LookupPatientMessage extends Message {

	/**
	 * First name of patient to look up
	 */
	private final String firstname;
	
	/**
	 * Last name of patient to look up
	 */
	private final String lastname;
	
	/**
	 * Initialize a LookupPatientMessage with a specified first
	 * and last name.
	 * @param firstname desired patient's first name
	 * @param lastname patient's last name
	 */
	public LookupPatientMessage(String firstname, String lastname) {
		super(new Object[]{firstname, lastname});
		this.firstname = firstname;
		this.lastname = lastname;
	}
	
	/**
	 * Lookup patient in the data model
	 * @param model data model to modify
	 * @return <code>UserListMessage</code> containing results
	 */
	@Override
	public Message handle(final DataModel model) {
		final List<Patient> results = model.lookupPatientByName(firstname, lastname);
		return new UserListMessage(results);
	}

	@Override public String toString() { // $codepro.audit.disable methodJavadoc
		return this.getPayload().toString();
	}
	
}
